// import Vue from 'vue'
// import Router from 'vue-router'
//
// Vue.use(Router)
//
// /* Layout */
// import Layout from '@/layout'
//
// export const constantRoutes = [
//   {
//     path: '/login',
//     component: () => import('@/views/login/index'),
//     hidden: true,
//     meta: { title: '登录', icon: 'form' }
//   },
//   {
//     path: '/404',
//     component: () => import('@/views/404'),
//     hidden: true
//   },
//   {
//     path: '/operationMonitoring',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'operationMonitoring',
//         component: () => import('@/views/operationMonitoring/index'),
//         meta: { title: '运行监测', icon: 'eye' }
//       },
//       {
//         hidden: true,
//         path: 'table',
//         name: 'operationMonitoring',
//         component: () => import('@/views/operationMonitoring/table'),
//         meta: { title: '运行监测-详情列表', icon: 'eye' },
//       },
//       {
//         hidden: true,
//         path: 'tableInside',
//         name: 'operationMonitoring',
//         component: () => import('@/views/operationMonitoring/tableInside'),
//         meta: { title: '运行监测-详情列表-所属设备', icon: 'eye' },
//       },
//     ]
//   },
//   {
//     path: '/GISSystem',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'GISSystem',
//         component: () => import('@/views/GISSystem/index'),
//         meta: { title: '管网系统', icon: 'international' }
//       }
//     ]
//   },
//   {
//     path: '/videoSurveillance',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'videoSurveillance',
//         component: () => import('@/views/videoSurveillance/index'),
//         meta: { title: '视频监控', icon: 'eye-open' }
//       }
//     ]
//   },
//   {
//     path: '/dataAnalysis',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'dataAnalysis',
//         component: () => import('@/views/dataAnalysis/index'),
//         meta: { title: '历史数据回顾', icon: 'documentation' }
//       }
//     ]
//   },
//   {
//     path: '/dataComparison',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'dataComparison',
//         component: () => import('@/views/dataComparison/index'),
//         meta: { title: '历史数据对比', icon: 'form' }
//       }
//     ]
//   },
//   {
//     path: '/waterSupplyForecast',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'waterSupplyForecast',
//         component: () => import('@/views/waterSupplyForecast/index'),
//         meta: { title: '供水预测', icon: 'people' }
//       }
//     ]
//   },
//   {
//     path: '/alarmInformation',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'alarmInformation',
//         component: () => import('@/views/alarmInformation/index'),
//         meta: { title: '报警信息', icon: 'message' }
//       }
//     ]
//   },
//   {
//     path: '/userManagement',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'userManagement',
//         component: () => import('@/views/userManagement/index'),
//         meta: { title: '用户管理', icon: 'peoples' }
//       }
//     ]
//   },
//   {
//     path: '/equipmentManagement',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'userManagement',
//         component: () => import('@/views/equipmentManagement/index'),
//         meta: { title: '仪器设备管理', icon: 'dashboard' }
//       }
//     ]
//   },
//   {
//     path: '/equipmentTypeManagement',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'userManagement',
//         component: () => import('@/views/equipmentTypeManagement/index'),
//         meta: { title: '仪器设备类型管理', icon: 'tab' }
//       }
//     ]
//   },
//   {
//     path: '/alarmTypeManagement',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'userManagement',
//         component: () => import('@/views/alarmTypeManagement/index'),
//         meta: { title: '报警类型管理', icon: 'message' }
//       }
//     ]
//   },
//   {
//     path: '/mapping',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         name: 'userManagement',
//         component: () => import('@/views/mapping/index'),
//         meta: { title: '字段与设备映射关系管理', icon: 'clipboard' }
//       }
//     ]
//   },
//
//
//
//   // 404 page must be placed at the end !!!
//   { path: '*', redirect: '/404', hidden: true }
// ]
//
// const createRouter = () => new Router({
//   // mode: 'history', // require service support
//   scrollBehavior: () => ({ y: 0 }),
//   routes: constantRoutes
// })
//
// const router = createRouter()
//
// // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// export function resetRouter() {
//   const newRouter = createRouter()
//   router.matcher = newRouter.matcher // reset router
// }
//
// export default router

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRouterMap = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta: { title: '登录', icon: 'form' }
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/operationMonitoring',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'operationMonitoring',
        component: () => import('@/views/operationMonitoring/index'),
        meta: { title: '运行监测', icon: 'eye' }
      },
      {
        hidden: true,
        path: 'table',
        name: 'operationMonitoring',
        component: () => import('@/views/operationMonitoring/table'),
        meta: { title: '运行监测-详情列表', icon: 'eye' },
      },
      {
        hidden: true,
        path: 'tableInside',
        name: 'operationMonitoring',
        component: () => import('@/views/operationMonitoring/tableInside'),
        meta: { title: '运行监测-详情列表-所属设备', icon: 'eye' },
      },
    ]
  },
  {
    path: '/videoSurveillance',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'videoSurveillance',
        component: () => import('@/views/videoSurveillance/index'),
        meta: { title: '视频监控', icon: 'eye-open' }
      }
    ]
  },
  {
    path: '/dataAnalysis',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'dataAnalysis',
        component: () => import('@/views/dataAnalysis/index'),
        meta: { title: '历史数据回顾', icon: 'documentation' }
      }
    ]
  },
  {
    path: '/dataComparison',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'dataComparison',
        component: () => import('@/views/dataComparison/index'),
        meta: { title: '历史数据对比', icon: 'form' }
      }
    ]
  },
  {
    path: '/waterSupplyForecast',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'waterSupplyForecast',
        component: () => import('@/views/waterSupplyForecast/index'),
        meta: { title: '供水预测', icon: 'people' }
      }
    ]
  },
  {
    path: '/alarmInformation',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'alarmInformation',
        component: () => import('@/views/alarmInformation/index'),
        meta: { title: '报警信息', icon: 'message' }
      }
    ]
  },
  {
    path: '/equipmentManagement',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'userManagement',
        component: () => import('@/views/equipmentManagement/index'),
        meta: { title: '仪器设备管理', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/equipmentTypeManagement',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'userManagement',
        component: () => import('@/views/equipmentTypeManagement/index'),
        meta: { title: '仪器设备类型管理', icon: 'tab' }
      }
    ]
  },
  {
    path: '/alarmTypeManagement',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'userManagement',
        component: () => import('@/views/alarmTypeManagement/index'),
        meta: { title: '报警类型管理', icon: 'message' }
      }
    ]
  },
  {
    path: '/userManagement',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'userManagement',
        component: () => import('@/views/userManagement/index'),
        meta: { title: '用户管理', icon: 'peoples' }
      }
    ]
  },
  {
    path: '/mapping',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'userManagement',
        component: () => import('@/views/mapping/index'),
        meta: { title: '字段与设备映射关系管理', icon: 'clipboard' }
      }
    ]
  },



  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRouterMap = [
  {
    path: '/GISSystem',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'GISSystem',
        component: () => import('@/views/GISSystem/index'),
        meta: { title: '管网系统', icon: 'international' }
      }
    ]
  }
]

let rs=constantRouterMap

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: rs
  })
const router = createRouter()


// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter(flag = false) {

  if ( flag == true ){
    // let temp = constantRouterMap.concat(asyncRouterMap)
    rs = constantRouterMap.concat(asyncRouterMap)
    router.options.routes = rs
    router.addRoutes(rs)
  }
  const newRouter = createRouter()
  console.log(router)
  router.matcher = newRouter.matcher // reset router
}

export default router
